<template>
  <el-dialog
    title="权限配置"
    :visible.sync="dialogValue"
    width="539px"
  >
    <div style="height: 400px;overflow:auto;">
      <el-tree
        ref="permissionTree"
        :data="permissionList"
        check-strictly
        show-checkbox
        :default-expanded-keys="checkedKeys"
        :default-checked-keys="checkedKeys"
        node-key="id"
        :props="defaultProps"
      />
    </div>
    <div slot="footer" class="f-r j-e">
      <el-button @click="onClose">取消</el-button>
      <el-button type="primary" @click="onSave">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { http_admin_user } from '@/api'

export default {
  name: 'ProjectTag',
  data() {
    return {
      dialogValue: false,
      permissionList: [
      ],
      ruleForm: {

      },
      checkedKeys: [],
      defaultProps: {
        children: 'children',
        label: 'menuName'
      },
      userId: ''
    }
  },
  methods: {
    open(item) {
      this.userId = item.id
      http_admin_user.getMenus().then(res => {
        this.permissionList = res.data
      })
      http_admin_user.get_permission(item.id).then(res => {
        this.checkedKeys = res.data.map(el => el.menuId)
      })
      this.dialogValue = true
    },
    onSave() {
      const ids = this.$refs.permissionTree.getCheckedKeys()
      http_admin_user.updatePermission({
        uid: this.userId,
        menuList: ids
      }).then(res => {
        this.$message.success(res.msg)
        this.dialogValue = false
      })
    },
    onClose() {
      this.dialogValue = false
    }
  }
}
</script>
<style lang="scss">
.tag-box{
  .line {
    border-bottom: 1px solid #CECECE;
  }
  margin: 30px 0 68px 0;
  .tag-list {
    .tag {
      padding: 0 28px;
      height: 38px;
      opacity: 1;
      border: 1px solid #999999;
      line-height: 38px;
      text-align: center;
      font-size: 16px;
      color: #999999;
      margin-right: 30px;
      border-radius: 6px;
      cursor: pointer;
      position: relative;
    }
    .tag.active {
      background-color: #DEE8FF;
      color: #4880FF;
      border-color: #4880FF;
    }
    .close-icon {
      color: red;
      position: absolute;
      top: -8px;
      right: -8px;
      background-color: red;
      display: inline-block;
      width: 18px;
      height: 18px;
      border-radius: 50%;
      i {
        font-size: 14px;
        position: absolute;
        left: 50%;
        top: 50%;
        transform: translate(-50%,-50%);
        color: #ffffff;
        line-height: 18px;
      }
    }
  }
}
</style>
